package com.boom.springapp.mystarterautoconfigure.autoconfigure;

import com.boom.springapp.mystarterautoconfigure.properties.HelloProperties;
import com.boom.springapp.mystarterautoconfigure.service.HelloService;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hhl
 * @version 1.0
 * @description
 * @date 2025/8/24 22:51
 */

@Configuration
@ConditionalOnClass(HelloService.class)
@EnableConfigurationProperties(HelloProperties.class)
@ConditionalOnProperty(prefix = "hello", name = "enabled", havingValue = "true", matchIfMissing = true)
public class HelloAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public HelloService helloService(HelloProperties helloProperties) {
        return new HelloService(helloProperties);
    }
}
